package com.state.impl;

import com.state.GumballMachine;
import com.state.face.State;

/**
 * 出售糖果状态
 * 
 * @author Administrator
 * 
 */
public class SoldState implements State {
	GumballMachine gumballMachine;

	public SoldState(GumballMachine gumballMachine) {
		this.gumballMachine = gumballMachine;
	}

	public void insertQuarter() {
		System.out.println("请等待，我们正在给你出售糖果");
	}

	public void ejectQuarter() {
		System.out.println("对不起，你已经转动了曲柄");
	}

	public boolean turnCrank() {
		System.out.println("转动两次曲柄也不能给你两次糖果");
		return false;
	}

	public void dispense() {
		gumballMachine.releaseBall();
		if (gumballMachine.getCount() > 0) {
			gumballMachine.setState(gumballMachine.getNoQuarterState());
		} else {
			System.out.println("对不起，没有糖果了");
			gumballMachine.setState(gumballMachine.getSoldOutState());
		}
	}

	public String toString() {
		return "正在出售糖果";
	}
}
